package xin.marcher.module.quality.mq.consumer;

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.exception.MQClientException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import xin.marcher.module.common.constants.RocketMqConstant;
import xin.marcher.module.quality.mq.config.RocketMQProperties;
import xin.marcher.module.quality.mq.consumer.listener.SurveyFormSendListener;


/**
 * 
 */
@Configuration
public class ConsumerBeanConfig {

    /**
     * 配置内容对象
     */
    @Autowired
    private RocketMQProperties rocketMQProperties;

    /**
     * 调查单状态变更，发送通知消息给用户
     *
     * @param surveyFormSendListener
     * @return
     * @throws MQClientException
     */
    @Bean("periodStageUpdateTopic")
    public DefaultMQPushConsumer createItemStageConsumer(SurveyFormSendListener surveyFormSendListener) throws MQClientException {
        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(RocketMqConstant.SURVEY_TASK_CHANGE_TOPIC);
        consumer.setNamesrvAddr(rocketMQProperties.getNameServer());
        consumer.subscribe(RocketMqConstant.INTERIOR_ITEM_QUALITY_SURVEY_TASK_TOPIC, "*");
        consumer.registerMessageListener(surveyFormSendListener);
        consumer.start();
        return consumer;
    }

}
